package cn.bdqn.dao.impl;

import cn.bdqn.dao.BaseDao;
import cn.bdqn.dao.StudentsDao;
import cn.bdqn.entity.Students;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: DELL
 * @Since: 2024/9/19 19:27
 * @Description:
 */
public class StudentsDaoImpl extends BaseDao implements StudentsDao {
    Students students;
    @Override
    public List<Students> getAll() {
        List<Students> All=new ArrayList<>();
        String sql="select * from students";
        ResultSet rs=null;
        try{
            rs=executeQuery(sql);
            while (rs.next()){
                students=new Students();
                students.setId(rs.getInt("id"));
                students.setName(rs.getString("name"));
                students.setAge(rs.getInt("age"));
                students.setGender(rs.getString("gender"));
                students.setMajor(rs.getString("major"));
                All.add(students);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            closeAll(connection,pstmt,rs);
        }
        return All;
    }
}
